//
// Created by 23602 on 25-8-24.
//

#ifndef COLORUTILS_HPP
#define COLORUTILS_HPP
#include  <SFML/Graphics.hpp>


#include <SFML/Graphics/Color.hpp>
#include <algorithm> // std::clamp

inline sf::Color operator*(const sf::Color& lhs, double factor)
{
    auto clamp = [](double value) -> uint8_t {
        return static_cast<uint8_t>(std::clamp(value, 0.0, 255.0));
    };

    return
    {
        clamp(lhs.r * factor),
        clamp(lhs.g * factor),
        clamp(lhs.b * factor),
        lhs.a // alpha 保持不变
    };;
}

inline sf::Color operator*(float factor, const sf::Color& rhs)
{
    return rhs * factor;
}

// inline Color operator+(const Color& c1, const Color& c2)
// {
//     Color res;
//     res.r = std::min(c1.r + c2.r, 255);
//     res.g = std::min(c1.g + c2.g, 255);
//     res.b = std::min(c1.b + c2.b, 255);
//     return res;
// }

#endif //COLORUTILS_HPP
